package com.atguigu.ssyx.activity.controller;

/**
 * @author 杨林
 * @create 2023-08-23 17:26 星期三
 * description:
 */

import com.atguigu.ssyx.activity.service.CouponInfoService;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.activity.CouponInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 优惠券接口
 */
@CrossOrigin
@RestController
@RequestMapping("/admin/activity/couponInfo")
public class CouponInfoController {
    
    @Autowired
    private CouponInfoService couponInfoService;

    /**
     * 获取优惠卷分页列表
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation(value = "获取分页列表")
    @GetMapping("/{page}/{limit}")
    public Result index(@ApiParam(name = "page",value = "当前页码",required = true) 
                        @PathVariable("page") Long page,
                        @ApiParam(name = "limit",value = "每页记录数",required = true)
                        @PathVariable("limit") Long limit){
        //构建分页条件
        IPage<CouponInfo> pageModel = couponInfoService.selectPage(page,limit);
        return Result.ok(pageModel);
    }

    /**
     * 根据id获取优惠券
     * @param id
     * @return
     */
    @ApiOperation(value = "获取优惠券")
    @GetMapping("/get/{id}")
    public Result getCouponInfoById(@PathVariable("id") String id){
        CouponInfo couponInfo = couponInfoService.getCouponInfoById(id);
        return Result.ok(couponInfo);
    }


    /**
     * 新增优惠券
     * @param couponInfo
     * @return
     */
    @ApiOperation(value = "新增优惠券")
    @PostMapping("/save")
    public Result save(@RequestBody CouponInfo couponInfo){
        couponInfoService.save(couponInfo);
        return Result.ok();
    }

    /**
     * 修改优惠券
     * @return
     */
    @ApiOperation(value = "修改优惠券")
    @PutMapping("/update")
    public Result update(@RequestBody CouponInfo couponInfo){
        
        couponInfoService.updateById(couponInfo);
        return Result.ok();
    }

    /**
     * 根据id删除优惠券
     * @return
     */
    @ApiOperation(value = "删除优惠券")
    @DeleteMapping("/remove/{id}")
    public Result removeById(@PathVariable("id") String id){
        couponInfoService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据id列表批量删除优惠券
     * @param idList
     * @return
     */
    @ApiOperation(value = "批量删除优惠券")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<String> idList){
        couponInfoService.removeBatchByIds(idList);
        return Result.ok();
    }


    /**
     * 根据优惠券id获取优惠券规则列表
     * @return
     */
    @ApiOperation(value = "获取优惠券信息")
    @GetMapping("/findCouponRuleList/{id}")
    public Result findActivityRuleList(@PathVariable("id") Long id){
        Map<String,Object> map = couponInfoService.findCouponRuleList(id);
        return Result.ok(map);
    }
    
    
    @ApiOperation(value = "新增活动")
    public Result saveCouponRule(){
        
        
        return null;
    }
    
}
